; Press Esc to terminate script, Pause/Break to "pause"
#include <Misc.au3>
#include <Color.au3>

Global $Keys[255]
$Keys[9]="{TAB}"
$Keys[13]="{ENTER}"
$Keys[27]="{ESC}"
$Keys[32]="{SPACE}"
$Keys[33]="{PGUP}"
$Keys[34]="{PGDN}"
$Keys[35]="{END}"
$Keys[36]="{HOME}"
$Keys[37]="{LEFT}"
$Keys[38]="{UP}"
$Keys[39]="{RIGHT}"
$Keys[40]="{DOWN}"
$Keys[45]="{INS}"
$Keys[46]="{DEL}"
$Keys[48]="0"
$Keys[49]="1"
$Keys[50]="2"
$Keys[51]="3"
$Keys[52]="4"
$Keys[53]="5"
$Keys[54]="6"
$Keys[55]="7"
$Keys[56]="8"
$Keys[57]="9"
$Keys[65]="a"
$Keys[66]="b"
$Keys[67]="c"
$Keys[68]="d"
$Keys[69]="e"
$Keys[70]="f"
$Keys[71]="g"
$Keys[72]="h"
$Keys[73]="i"
$Keys[74]="j"
$Keys[75]="k"
$Keys[76]="l"
$Keys[77]="m"
$Keys[78]="n"
$Keys[79]="o"
$Keys[80]="p"
$Keys[81]="q"
$Keys[82]="r"
$Keys[83]="s"
$Keys[84]="t"
$Keys[85]="u"
$Keys[86]="v"
$Keys[87]="w"
$Keys[88]="x"
$Keys[89]="y"
$Keys[90]="z"
$Keys[91]="{LWIN}"
$Keys[92]="{RWIN}"
$Keys[93]="{APPSKEY}"
$Keys[97]="{NUMPAD1}"
$Keys[98]="{NUMPAD2}"
$Keys[99]="{NUMPAD3}"
$Keys[100]="{NUMPAD4}"
$Keys[101]="{NUMPAD5}"
$Keys[102]="{NUMPAD6}"
$Keys[103]="{NUMPAD7}"
$Keys[104]="{NUMPAD8}"
$Keys[105]="{NUMPAD9}"
$Keys[112]="{F1}"
$Keys[113]="{F2}"
$Keys[114]="{F3}"
$Keys[115]="{F4}"
$Keys[116]="{F5}"
$Keys[117]="{F6}"
$Keys[118]="{F7}"
$Keys[119]="{F8}"
$Keys[120]="{F9}"
$Keys[121]="{F10}"
$Keys[122]="{F11}"
$Keys[123]="{F12}"
$Keys[186]=";"
$Keys[187]="="
$Keys[188]=","
$Keys[189]="-"
$Keys[190]="."
$Keys[191]="/"
$Keys[192]="`"
$Keys[219]="["
$Keys[220]="\"
$Keys[221]="]"
$Keys[222]="'"

Local $hDLL = DllOpen("user32.dll")

Global $Paused = False
Global $keyspamspeed = 50
HotKeySet("{ENTER}", "TimeToChat")
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("+{ESC}", "Terminate")

;;;; Body of program would go here ;;;;
WinWaitActive("RIFT")
While 1
  if not _IsPressed("10", $hDLL) then
	 if not $Paused then
		Local $KeyColor_red = _ColorGetRed("0x" & Hex(PixelGetColor(5,5)))
		Local $KeyColor_green = _ColorGetGreen("0x" & Hex(PixelGetColor(5,5)))
		Local $KeyColor_blue = _ColorGetBlue("0x" & Hex(PixelGetColor(5,5)))
		 if $KeyColor_green == 0 and $KeyColor_blue == 0 Then
			Send($Keys[$KeyColor_red])
		 EndIf
		Sleep($keyspamspeed)
	 else
		Sleep($keyspamspeed)
	 endif
  else
	 Sleep($keyspamspeed)
  endif
WEnd
;;;;;;;;

Func TimeToChat()
HotKeySet("{ENTER}")
Send("{ENTER}")
HotKeySet("{ENTER}", "TimeToChat")
TogglePause()
EndFunc

Func TogglePause()
$Paused = Not $Paused
EndFunc ;==>TogglePause

Func Terminate()
Exit 0
EndFunc ;==>Terminate